import java.util.Random;
import java.util.ArrayList;
public class Run {
    public static void main(String[] args) {
        TheClass class1 = new TheClass("班级1");
        TheClass class2 = new TheClass("班级2");

        Student[] classStudent1 = {
                new Student("五加一"),new Student("王乐乐"),new Student("赵青青"),
                new Student("刘金金"),new Student("卢珊珊"),new Student("羊毛月"),new Student("王早晨"),
                new Student("彭艺术"),new Student("王光荣"),new Student("朱萌萌"),};
        for (Student student : classStudent1) {
            class1.addStudent(student);
        }
        Group[] group1 = {
                new Group("飞天组"), new Group("干饭组"), new Group("哈哈组"),
                new Group("小六饭"), new Group("很多很多组")
        };
        for (Group group : group1) {
            class1.addGroup(group);
        }
        distributeStudentsToGroups(class1.students, group1);

        // 添加学生到班级二
        Student[] students2 = {
                new Student("物价二"), new Student("物价三"), new Student("物价四"),
                new Student("赵灵"), new Student("赵青"), new Student("赵赵"),
                new Student("王五"), new Student("王佳一"), new Student("王加二"), new Student("赵加三")
        };
        for (Student student : students2) {
            class2.addStudent(student);
        }

        // 添加小组到班级二
        Group[] group2 = {
                new Group("小组六"), new Group("小组七"), new Group("小组八"),
                new Group("小组九"), new Group("小组十")
        };
        for (Group group : group2) {
            class2.addGroup(group);
        }
        distributeStudentsToGroups(class2.students, group2);
        // 在两个班级中抽取一个同学
        Student selectedStudentFromTwoClasses = selectStudentFromTwoClasses(class1, class2);
        System.out.println("从两个班级中抽取的同学是：" + selectedStudentFromTwoClasses.getName());

        // 在两个班级中抽取一个班级，再从该班级中抽取一个同学
        Student selectedStudentFromSelectedClass = selectStudentFromSelectedClass(class1, class2);
        System.out.println("从抽取的班级中抽取的同学是：" + selectedStudentFromSelectedClass.getName());

        // 在两个班级中抽取一个班级，在这个班级中抽取一个小组，从这个小组中抽取一个同学
        Student selectedStudentFromGroupInSelectedClass = selectStudentFromGroupInSelectedClass(class1, class2);
        System.out.println("从抽取的小组中抽取的同学是：" + selectedStudentFromGroupInSelectedClass.getName());
    }


    private static void distributeStudentsToGroups(ArrayList<Student> students, Group[] groups) {
        int studentIndex = 0;
        for (Group group : groups) {
            while (group.students.size() < 2 && studentIndex < students.size()) {
                group.addStudent(students.get(studentIndex));
                studentIndex++;
            }
        }
    }

    public static Student selectStudentFromTwoClasses(TheClass class1, TheClass class2) {
        Random random = new Random();
        boolean selectClassRoom1 = random.nextBoolean();
        if (selectClassRoom1) {
            return class1.selectStudent();
        } else {
            return class2.selectStudent();
        }
    }

    public static Student selectStudentFromSelectedClass(TheClass class1, TheClass class2) {
        Random random = new Random();
        boolean selectClassRoom1 = random.nextBoolean();
        TheClass selectedClassRoom = selectClassRoom1? class1 : class2;
        return selectedClassRoom.selectStudent();
    }

    public static Student selectStudentFromGroupInSelectedClass(TheClass class1, TheClass class2) {
        Random random = new Random();
        boolean selectClassRoom1 = random.nextBoolean();
        TheClass selectedClassRoom = selectClassRoom1? class1 : class2;
        Group selectedGroup = selectedClassRoom.selectGroup();
        return selectedGroup.selectStudent();
    }

}
//public class Run {
//    public static void main(String[] args) {
//        Student student = new Student();
//        student.GroupInf();
//    }
//}
